﻿#region Imports
using System.Collections.Generic;
using System.IO;
using System.Linq;
#endregion

namespace BulkRenamer.App.Controls
{
    /// <summary>
    /// Skips forbidden (system) directories while fetching 
    /// </summary>
    public class BRDirectory
    {
        #region Methods
        /// <summary>
        /// Gets the names of subdirectories in the specified directory.
        /// <para> _</para>
        /// <para>  System.UnauthorizedAccessException:</para>
        /// <para>    The caller does not have the required permission.</para>
        /// <para> _</para>
        /// <para>  System.ArgumentException:</para>
        /// <para>    path is a zero-length string, contains only white space, or contains one</para>
        /// <para>    or more invalid characters as defined by System.IO.Path.InvalidPathChars.</para>
        /// <para> _</para>
        /// <para>  System.ArgumentNullException:</para>
        /// <para>    path is null.</para>
        /// <para> _</para>
        /// <para>  System.IO.PathTooLongException:</para>
        /// <para>    The specified path, file name, or both exceed the system-defined maximum</para>
        /// <para>    length. For example, on Windows-based platforms, paths must be less than</para>
        /// <para>    248 characters and file names must be less than 260 characters.</para>
        /// <para> _</para>
        /// <para>  System.IO.IOException:</para>
        /// <para>    path is a file name.</para>
        /// <para> _</para>
        /// <para>  System.IO.DirectoryNotFoundException:</para>
        /// <para>    The specified path is invalid (for example, it is on an unmapped drive).</para>
        /// </summary>
        /// <param name="path">Path for which an array of subdirectory names is returned</param>
        /// <returns>Array of the names of subdirectories in specified path</returns>
        public static string[] GetDirectories(string path)
        {
            return Directory.GetDirectories(path)
                .Where(dir => !Program.ForbiddenDirectories.Contains(GetDirectoryName(dir))).ToArray();
        }

        /// <summary>
        /// Fetches directory name from specified path
        /// </summary>
        /// <param name="path">Path to evluate</param>
        /// <returns>Directory name for the specified path</returns>
        public static string GetDirectoryName(string path)
        {
            return new DirectoryInfo(path).Name;
        }
        #endregion
    }
}
